﻿
Public Class wysTextBox

    Private _长度类型 As 长度型 = 长度型.字符
    Public Property 长度类型() As 长度型
        Get
            Return _长度类型
        End Get
        Set(ByVal value As 长度型)
            _长度类型 = value
        End Set
    End Property

    Private Sub wysTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        'backspace
        If UTILControl.GetStringLength(Me.Text, 长度类型) >= MaxLength Then
            If Not (Char.IsLetterOrDigit(e.KeyChar) OrElse Char.IsSymbol(e.KeyChar) OrElse Char.IsWhiteSpace(e.KeyChar)) Then
                Return
            End If
            e.Handled = True
        End If
    End Sub

    Private Sub wysTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.TextChanged

        Me.Text = UTILControl.CutString(Me.Text, Me.MaxLength, 长度类型)
        Me.SelectionStart = Me.Text.TrimEnd.Length
    End Sub

End Class
